package cn.harry.cabinet.dao

import androidx.room.*
import cn.harry.cabinet.model.entity.Configuration

/**
 * 配置表数据访问对象
 */
@Dao
interface ConfigurationDao {
    
    @Query("SELECT * FROM configurations")
    fun getAllConfigurations(): List<Configuration>
    
    @Query("SELECT * FROM configurations WHERE id = :id")
    fun getConfigurationById(id: Long): Configuration?
    
    @Query("SELECT * FROM configurations WHERE type = :type")
    fun getConfigurationsByType(type: String): List<Configuration>
    
    @Query("SELECT * FROM configurations WHERE `key` = :key LIMIT 1")
    fun getConfigurationByKey(key: String): Configuration?
    
    @Query("SELECT * FROM configurations WHERE type = :type AND `key` = :key LIMIT 1")
    fun getConfigurationByTypeAndKey(type: String, key: String): Configuration?
    
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertConfiguration(configuration: Configuration): Long
    
    @Update
    fun updateConfiguration(configuration: Configuration)
    
    @Delete
    fun deleteConfiguration(configuration: Configuration)
    
    @Query("DELETE FROM configurations")
    fun deleteAllConfigurations()
}